package logic

import (
	"context"
	"github.com/google/uuid"

	"worker/sse/internal/svc"
	"worker/sse/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type JoinGroupLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewJoinGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *JoinGroupLogic {
	return &JoinGroupLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *JoinGroupLogic) JoinGroup(req *types.JoinGroupReq) (resp *types.JoinGroupResp, err error) {
	resp = &types.JoinGroupResp{Ok: true}
	uuid1, err := uuid.Parse(req.ClientId)
	if err != nil {
		logx.Error(err)
		resp.Ok = false
		return resp, err
	}
	l.svcCtx.SSE.JoinGroup(uuid1, req.GroupId)

	return resp, nil
}
